package com.siruier.boss.api

import com.siruier.boss.api.core.ApiHelper
import com.siruier.boss.api.core.ResultBean
import kotlinx.coroutines.CoroutineScope
import okhttp3.RequestBody
import retrofit2.http.*

val LOGIN_API_SERVICE: LoginApiService by lazy { ApiHelper.create(LoginApiService::class.java) }

val CoroutineScope.loginApi get() = LOGIN_API_SERVICE

interface LoginApiService {

    /**
     * 手机账号登录
     */
    @POST("/api/user/login")
    @FormUrlEncoded
    suspend fun phoneLogin(
        @Field("phone") phone: String,
        @Field("password") password: String,
        @Field("imei") imei: String?,
        @Field("isRoot") isRoot: Int,
        @Field("isBeingTraced") isBeingTraced: Int,
        @Field("isXposed") isXposed: Int,
        @Field("isVirtual") isVirtual: Int,
        @Field("isEmulator") isEmulator: Int,
        @Field("isVpn") isVpn: Int,
    ): ResultBean<AccessTokenBean?>

    /**
     * 获取用户信息
     */
    @GET("/api/user/userInfo")
    suspend fun userInfo(): ResultBean<UserInfoBean?>

    /**
     * 服务商升级
     */
    @GET("/api/user/upSP")
    suspend fun upSP(): ResultBean<Any?>

    /**
     * 用户注册
     */
    @POST("/api/user/register")
    @FormUrlEncoded
    suspend fun register(
        @Field("phone") phone: String,
        @Field("password") password: String,
        @Field("code") code: String,
        @Field("invitePhone") invitePhone: String,
    ): ResultBean<Any?>

    /**
     * 修改登录密码
     */
    @POST("/api/user/updatePwd")
    @FormUrlEncoded
    suspend fun updatePwd(
        @Field("phone") phone: String,
        @Field("password") password: String,
        @Field("code") code: String,
    ): ResultBean<Any?>

    /**
     * 发送短信
     */
    @POST("/api/sms/send")
    @FormUrlEncoded
    suspend fun smsSend(
        @Field("phone") phone: String,
        @Field("type") type: String,
    ): ResultBean<Any?>

    /**
     * 修改支付密码
     */
    @POST("/api/user/updatePayPwd")
    @FormUrlEncoded
    suspend fun updatePayPwd(
        @Field("phone") phone: String,
        @Field("password") password: String,
        @Field("code") code: String,
    ): ResultBean<Any?>

    /**
     * 文件上传
     */
    @POST("/api/sys/upload")
    suspend fun fileUpload(@Body body: RequestBody): ResultBean<FileInfo?>

    /**
     * 实名认证
     */
    @POST("/api/user/idCardAuth")
    @FormUrlEncoded
    suspend fun idCardAuth(
        @Field("name") name: String,
        @Field("idCardNo") idCardNo: String,
        @Field("phone") phone: String,
        @Field("code") code: String,
        @Field("bankName") bankName: String,
        @Field("cardNo") cardNo: String,
        @Field("idCardFrontImg") idCardFrontImg: String?,
        @Field("idCardBackImg") idCardBackImg: String?,
        @Field("licenseUrl") licenseUrl: String?,
        @Field("shopUrl") shopUrl: String?,
        @Field("type") type: Int,
    ): ResultBean<Any?>

    /**
     * 余额提现
     */
    @POST("/api/user/withdraw")
    @FormUrlEncoded
    suspend fun withdraw(
        @Field("amount") amount: String,
        @Field("busiType") busiType: Int,
        @Field("payPassword") payPassword: String,
    ): ResultBean<MutableMap<String, String>?>

    /**
     * 我的客户明细
     */
    @POST("/api/user/customerRecord")
    @FormUrlEncoded
    suspend fun customerRecord(
        @Field("currentPage") currentPage: Int,
        @Field("level") level: Int?,
        @Field("phone") phone: String,
        @Field("pageSize") pageSize: Int = 20,
    ): ResultBean<PageBean<CustomerRecord>?>

    /**
     * 公告已读，不再提示
     */
    @POST("/api/sys/noticeRead")
    @FormUrlEncoded
    suspend fun noticeRead(
        @Field("id") id: Int,
    ): ResultBean<Any?>

    /**
     * 获取最新公告
     */
    @GET("/api/sys/notice")
    suspend fun newNotice(): ResultBean<NoticeBean?>

    /**
     * 获取公告
     */
    @POST("/api/sys/noticeList")
    @FormUrlEncoded
    suspend fun noticeList(
        @Field("currentPage") currentPage: Int,
        @Field("pageSize") pageSize: Int = 20,
    ): ResultBean<PageBean<NoticeBean>?>

    /**
     * 获取最新公告
     */
    @GET("/api/sys/notice")
    suspend fun notice(): ResultBean<MutableList<BannerBean>?>

    /**
     * 我的客户统计
     */
    @GET("/api/user/customerTotal")
    suspend fun customerTotal(): ResultBean<CustomerTotal?>

    /**
     * 我的余额概况
     */
    @GET("/api/user/balanceTotal")
    suspend fun balanceTotal(): ResultBean<BalanceTotal?>

    /**
     * 获取提现记录
     */
    @POST("/api/user/withdrawRecord")
    @FormUrlEncoded
    suspend fun withdrawRecord(
        @Field("currentPage") currentPage: Int,
        @Field("pageSize") pageSize: Int = 20,
    ): ResultBean<PageBean<UserWithdrawal>?>

    /**
     * 撤销提现
     */
    @POST("/api/user/cancelWithdraw")
    @FormUrlEncoded
    suspend fun cancelWithdraw(
        @Field("id") id: Int,
    ): ResultBean<Any?>

    /**
     * 获取用户余额明细
     */
    @POST("/api/user/integralLog")
    @FormUrlEncoded
    suspend fun integralLog(
        @Field("startTime") startTime: String?,
        @Field("endTime") endTime: String?,
        @Field("currentPage") currentPage: Int,
        @Field("pageSize") pageSize: Int = 20,
    ): ResultBean<PageBean<UserIntegralBean>?>

    /**
     * 设置客户备注
     */
    @POST("/api/user/setRemark")
    @FormUrlEncoded
    suspend fun setRemark(
        @Field("remark") remark: String?,
        @Field("userId") userId: Int?,
    ): ResultBean<Any?>

    /**
     * 获取挂卖余额明细
     */
    @POST("/api/user/balanceLog")
    @FormUrlEncoded
    suspend fun balanceLog(
        @Field("startTime") startTime: String?,
        @Field("endTime") endTime: String?,
        @Field("currentPage") currentPage: Int,
        @Field("pageSize") pageSize: Int = 20,
    ): ResultBean<PageBean<UserIntegralBean>?>

    /**
     * 获取市场贡献值明细
     */
    @POST("/api/user/areaIncomeLog")
    @FormUrlEncoded
    suspend fun areaIncomeLog(
        @Field("startTime") startTime: String?,
        @Field("endTime") endTime: String?,
        @Field("currentPage") currentPage: Int,
        @Field("pageSize") pageSize: Int = 20,
    ): ResultBean<PageBean<AreaIncomeLogBean>?>

    /**
     * 获取Banner
     * @param position 广告位置：1-首页 2-加盟区 3-0元区
     */
    @POST("/api/sys/banner")
    @FormUrlEncoded
    suspend fun banner(
        @Field("position") position: Int,
    ): ResultBean<MutableList<BannerBean>?>

    /**
     * 获取微信Openid
     */
    @POST("/api/user/getOpId")
    @FormUrlEncoded
    suspend fun getOpId(
        @Field("code") code: String,
    ): ResultBean<WeiXiBean?>

    /**
     * 第三方登录
     */
    @POST("/api/user/trdLogin")
    @FormUrlEncoded
    suspend fun trdLogin(
        @Field("authCode") authCode: String,
        @Field("channel") channel: String = "1",
        @Field("imei") imei: String = "",
    ): ResultBean<TrdLoginInfo?>

    /**
     * 获取最新版本
     */
    @POST("/api/sys/version")
    @FormUrlEncoded
    suspend fun version(
        @Field("version") version: String,
        @Field("appType") authCode: String = "2",
    ): ResultBean<VersionBean?>

    /**
     * 修改昵称
     */
    @POST("/api/user/updateName")
    @FormUrlEncoded
    suspend fun updateName(
        @Field("name") name: String,
    ): ResultBean<Any?>

    /**
     * 视频奖励
     */
    @POST("/api/task/vrd")
    @FormUrlEncoded
    suspend fun taskVrd(
        @Field("timestamp") timestamp: Long,
    ): ResultBean<Any?>

    /**
     * 修改头像
     */
    @POST("/api/user/updateAvatar")
    @FormUrlEncoded
    suspend fun updateAvatar(
        @Field("avatar") avatar: String,
    ): ResultBean<Any?>

    /**
     * 获取配置
     */
    @GET("/api/sys/sysConfig")
    suspend fun sysConfig(): ResultBean<SysConfig?>

    /**
     * 个人中心页面统计
     */
    @GET("/api/user/userCount")
    suspend fun userCount(): ResultBean<UserCount?>

    /**
     * 获取加油宝地址
     */
    @GET("/api/trd/jyUrl")
    suspend fun trdJyUrl(): ResultBean<TrdJyUrl?>

    /**
     * 获取话费充值地址
     */
    @GET("/api/trd/hfUrl")
    suspend fun trdHfUrl(): ResultBean<TrdJyUrl?>
}